﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using SwenAssignment3.Classes;

namespace SwenAssignment3.RoomAvailabilityCumBookingModule
{
    public partial class RoomCheckOut : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            dlRoomList.DataSource = DRHotelDBManager.retrieveAllRooms();
            dlRoomList.DataBind();
        }

        HiddenField roomStatus;
        LinkButton roomNo;

        // Binding the CSS Style of item in the DataList to Database..
        protected void dlRoomList_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            roomStatus = (HiddenField)e.Item.FindControl("RoomStatus");
            roomNo = (LinkButton)e.Item.FindControl("RoomButton");

            if (roomStatus.Value == "O")
            {
                roomNo.CssClass = "OccupiedRoom";
            }
            else if (roomStatus.Value == "SFC")
            {
                roomNo.CssClass = "SFCRoom";
            }
            else
            {
                roomNo.CssClass = "VacantRoom";
            }
        }

        protected void dlRoomList_ItemCommand(object source, DataListCommandEventArgs e)
        {
            if (e.CommandName == "RoomButtonClick")
            {
                roomNo = e.Item.FindControl("RoomButton") as LinkButton;
                if (roomNo.CssClass == "OccupiedRoom")
                {
                    //If Room Status = Occupied
                    roomNo.CssClass = "SelectedRoom";
                    
                    //Direct to generate Invoice
                    Response.Redirect("GenerateInvoice.aspx?RoomNo=" + roomNo.Text);
                }
                else if (roomNo.CssClass == "SFC")
                {
                    //If Room Status = Scheduled For Cleaning
                    roomNo.CssClass = "SelectedRoom";

                    //Direct to remove SFC
                }
                else
                {
                    //Do nothing
                }
            }
        }
    }
}